// pages/myorder/myorder.js
Page({

  /**
   * 页面的初始数据
   */
  data: {

    state: '',
    myOrder: [
      {
        "totalPrice": 99,
        "paymentMethod": "支付宝",
        "createdAt": "2024-10-24T11:15:40.000+00:00",
        "updatedAt": "2024-12-26T13:41:52.000+00:00",
        "notes": null,
        "orderid": "ORD202412081000000001234560214",
        "startservicetime": "2024-12-26T13:41:33.000+00:00",
        "endservicetime": "2024-12-26T13:41:27.000+00:00",
        "address": null,
        "orderdetailList": [
          {
            "id": 1,
            "orderid": "ORD202412081000000001234560214",
            "servicename": "上门",
            "price": 100,
            "picurl": "http://192.168.101.65:9000/photos/1/servicepic/10a80123538ed681d323cc26494060ad.png",
            "serviceid": 17,
            "acceptid": 1,
            "acceptname": "王华",
            "createat": "2024-12-09T08:11:10.000+00:00",
            "accepttel": "15896542233",
            "status": 1,
            "specification": "餐点份量/单餐（1-2人）/99",
            "address": "河南省郑州市金水区龙子湖",
            "updateat": "2024-12-09T08:11:10.000+00:00"
          },
          {
            "id": 6,
            "orderid": "ORD202412081000000001234560214",
            "servicename": "上门",
            "price": 100,
            "picurl": "http://192.168.101.65:9000/photos/1/servicepic/10a80123538ed681d323cc26494060ad.png",
            "serviceid": 17,
            "acceptid": 1,
            "acceptname": "王华",
            "createat": "2024-12-09T08:11:08.000+00:00",
            "accepttel": "12368899654",
            "status": 1,
            "specification": "餐点份量/单餐（1-2人）/99",
            "address": "河南省郑州市金水区福苑小区",
            "updateat": "2024-12-09T08:11:08.000+00:00"
          },
          {
            "id": 7,
            "orderid": "ORD202412081000000001234560214",
            "servicename": "上门",
            "price": 100,
            "picurl": "http://192.168.101.65:9000/photos/1/servicepic/10a80123538ed681d323cc26494060ad.png",
            "serviceid": 17,
            "acceptid": 1,
            "acceptname": "王华",
            "createat": "2024-12-09T08:11:08.000+00:00",
            "accepttel": "12368899654",
            "status": 1,
            "specification": "餐点份量/单餐（1-2人）/99",
            "address": "河南省郑州市金水区龙子湖",
            "updateat": "2024-12-09T08:11:08.000+00:00"
          }
        ]
      },
      {
        "totalPrice": 99,
        "paymentMethod": "支付宝",
        "createdAt": "2024-10-25T11:15:40.000+00:00",
        "updatedAt": "2024-12-26T13:41:52.000+00:00",
        "notes": null,
        "orderid": "ORD202412081000000001234560215",
        "startservicetime": "2024-12-26T13:41:34.000+00:00",
        "endservicetime": "2024-12-26T13:41:29.000+00:00",
        "address": null,
        "orderdetailList": [
          {
            "id": 2,
            "orderid": "ORD202412081000000001234560215",
            "servicename": "上门",
            "price": 100,
            "picurl": "http://192.168.101.65:9000/photos/1/servicepic/10a80123538ed681d323cc26494060ad.png",
            "serviceid": 17,
            "acceptid": 2,
            "acceptname": "李飞升",
            "createat": "2024-12-09T08:11:08.000+00:00",
            "accepttel": "15336969855",
            "status": 2,
            "specification": "餐点份量/单餐（1-2人）/99",
            "address": "河南省郑州市金水区福苑小区",
            "updateat": "2024-12-09T08:11:08.000+00:00"
          }
        ]
      },
      {
        "totalPrice": 55,
        "paymentMethod": "微信",
        "createdAt": "2024-10-24T14:44:56.000+00:00",
        "updatedAt": "2024-12-26T13:41:52.000+00:00",
        "notes": null,
        "orderid": "ORD202412081000000001234560216",
        "startservicetime": "2024-12-26T13:41:35.000+00:00",
        "endservicetime": "2024-12-26T13:41:37.000+00:00",
        "address": null,
        "orderdetailList": [
          {
            "id": 3,
            "orderid": "ORD202412081000000001234560216",
            "servicename": "上门",
            "price": 100,
            "picurl": "http://192.168.101.65:9000/photos/1/servicepic/10a80123538ed681d323cc26494060ad.png",
            "serviceid": 17,
            "acceptid": 3,
            "acceptname": "张伟",
            "createat": "2024-12-09T08:11:10.000+00:00",
            "accepttel": "12336696699",
            "status": 2,
            "specification": "餐点份量/单餐（1-2人）/99",
            "address": "河南省郑州市金水区龙子湖",
            "updateat": "2024-12-09T08:11:10.000+00:00"
          }
        ]
      },
      {
        "totalPrice": 99,
        "paymentMethod": "微信",
        "createdAt": "2024-11-17T14:05:13.000+00:00",
        "updatedAt": "2024-12-26T13:41:52.000+00:00",
        "notes": null,
        "orderid": "ORD202412081000000001234560218",
        "startservicetime": "2024-12-26T13:41:40.000+00:00",
        "endservicetime": "2024-12-26T13:41:41.000+00:00",
        "address": null,
        "orderdetailList": [
          {
            "id": 5,
            "orderid": "ORD202412081000000001234560218",
            "servicename": "上门",
            "price": 100,
            "picurl": "http://192.168.101.65:9000/photos/1/servicepic/10a80123538ed681d323cc26494060ad.png",
            "serviceid": 17,
            "acceptid": 1,
            "acceptname": "王华",
            "createat": "2024-12-09T08:11:10.000+00:00",
            "accepttel": "12368899654",
            "status": 1,
            "specification": "餐点份量/单餐（1-2人）/99",
            "address": "河南省郑州市金水区龙子湖",
            "updateat": "2024-12-09T08:11:10.000+00:00"
          }
        ]
      },
      {
        "totalPrice": 150.5,
        "paymentMethod": "支付宝",
        "createdAt": "2024-12-17T08:53:38.000+00:00",
        "updatedAt": "2024-12-17T08:53:38.000+00:00",
        "notes": "请尽快送",
        "orderid": "ORD202412171653379701kurl",
        "startservicetime": "2024-12-17T08:53:38.000+00:00",
        "endservicetime": "2024-12-17T08:53:38.000+00:00",
        "address": "天津市河西区大沽南路1310号‌",
        "orderdetailList": [
          {
            "id": 13,
            "orderid": "ORD202412171653379701kurl",
            "servicename": "Room Cleaning",
            "price": 50,
            "picurl": "https://example.com/images/room-cleaning.jpg",
            "serviceid": 101,
            "acceptid": null,
            "acceptname": null,
            "createat": "2024-12-17T08:53:38.000+00:00",
            "accepttel": null,
            "status": 0,
            "specification": "Standard",
            "address": "天津市河西区大沽南路1310号‌",
            "updateat": "2024-12-17T08:53:38.000+00:00"
          },
          {
            "id": 14,
            "orderid": "ORD202412171653379701kurl",
            "servicename": "Laundry Service",
            "price": 100.5,
            "picurl": "https://example.com/images/laundry-service.jpg",
            "serviceid": 102,
            "acceptid": null,
            "acceptname": null,
            "createat": "2024-12-17T08:53:38.000+00:00",
            "accepttel": null,
            "status": 0,
            "specification": "Express",
            "address": "天津市河西区大沽南路1310号‌",
            "updateat": "2024-12-17T08:53:38.000+00:00"
          }
        ]
      },
      {
        "totalPrice": 150.5,
        "paymentMethod": "支付宝",
        "createdAt": "2024-12-23T02:44:50.000+00:00",
        "updatedAt": "2024-12-26T13:41:52.000+00:00",
        "notes": null,
        "orderid": "ORD2024122310445037014f6l",
        "startservicetime": "2024-12-26T13:41:44.000+00:00",
        "endservicetime": "2024-12-26T13:41:46.000+00:00",
        "address": null,
        "orderdetailList": [
          {
            "id": 15,
            "orderid": "ORD2024122310445037014f6l",
            "servicename": "Room Cleaning",
            "price": 50,
            "picurl": "https://example.com/images/room-cleaning.jpg",
            "serviceid": 101,
            "acceptid": null,
            "acceptname": null,
            "createat": "2024-12-23T02:44:50.000+00:00",
            "accepttel": null,
            "status": -1,
            "specification": "Standard",
            "address": null,
            "updateat": "2024-12-23T02:44:50.000+00:00"
          },
          {
            "id": 16,
            "orderid": "ORD2024122310445037014f6l",
            "servicename": "Laundry Service",
            "price": 100.5,
            "picurl": "https://example.com/images/laundry-service.jpg",
            "serviceid": 102,
            "acceptid": null,
            "acceptname": null,
            "createat": "2024-12-23T02:44:50.000+00:00",
            "accepttel": null,
            "status": -1,
            "specification": "Express",
            "address": null,
            "updateat": "2024-12-23T02:44:50.000+00:00"
          }
        ]
      }
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  comOrder(){
    this.data.myOrder.forEach(myOrder => {
      // 遍历每个 orderdetailList 项
      myOrder.orderdetailList.forEach(orderDetail => {
          // 分割 specification 字符串并只保留第二个元素
          const parts = orderDetail.specification.split("/");
          orderDetail.specification = parts[1];  // 只保留第二个元素
  
          // 打印更新后的 specification
          console.log(orderDetail.specification);
      });
  });
    this.setData({
      myOrder: this.data.myOrder
    });
    console.log(this.data.myOrder);

  },
  onChange(event) {
 switch(event.detail.index){
   case  0:
   console.log(0);
    this.getAllSelfOrder();
   break;
   case 1:
     console.log(1);
     this.getDoorstep();
     break;
     case 2:
      console.log(2);
      this.getInService();
      break;
      case 3:
     console.log(3);
     this.getCompleted();
     break;
 }
  
  },

  getAllSelfOrder(){
       wx.request({
         url: 'http://localhost:9001/wx/getSelfOrder',
         withCredentials: true, 
         header: {
          'Cookie': wx.getStorageSync('sessionID') // 从本地存储中获取 JSESSIONID
        },
         method:'GET',
         success:(res)=>{
           this.setData({
             myOrder:res.data.data
           })
           this.comOrder();
         }
       })
  },

  getDoorstep(){
    wx.request({
      url: 'http://localhost:9001/wx/getDoorstep',
      withCredentials: true, 
      header: {
       'Cookie': wx.getStorageSync('sessionID') // 从本地存储中获取 JSESSIONID
     },
      method:'GET',
      success:(res)=>{
        this.setData({
          myOrder:res.data.data
        })
        this.comOrder();
      }
    })
},
getInService(){
  wx.request({
    url: 'http://localhost:9001/wx/getInService',
    withCredentials: true, 
    header: {
     'Cookie': wx.getStorageSync('sessionID') // 从本地存储中获取 JSESSIONID
   },
    method:'GET',
    success:(res)=>{
      this.setData({
        myOrder:res.data.data
      })
      this.comOrder();
    }
  })
},
getCompleted(){
  wx.request({
    url: 'http://localhost:9001/wx/getCompleted',
    withCredentials: true, 
    header: {
     'Cookie': wx.getStorageSync('sessionID') // 从本地存储中获取 JSESSIONID
   },
    method:'GET',
    success:(res)=>{
      this.setData({
        myOrder:res.data.data
      })
      this.comOrder();
    }
  })
},

  onLoad(options) {

   
 console.log(options.state);
    this.setData({
      state:options.state
    })
    console.log(this.data.state);
    const state = options.state;
    console.log('State:', state); // 打印出 1
   switch (state){
   case '0':
    console.log(1);
    this.getAllSelfOrder();
    break;
   case'1':
   console.log(2);
   this.getDoorstep();
   break;
   case'2':
   console.log(2);
   this.getInService();
    break;
  case'3':
  console.log(2);
  this.getCompleted();
  break;
  }

 

    this.getAllSelfOrder();
    this.comOrder();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})